<template>
	<view>
		<view class="input-group">
			<view class="flex-row input-view">
				<image class="input-left-img" src="../../static/img/user.png" mode="scaleToFill"></image>
				<view class="search-input">
					<input class="search-input" type="text" placeholder-class="input-placeholder" placeholder="请输入账号"
						v-model="userCode" :focus="isFocus" @confirm="checkUser">
				</view>
			</view>
			<view class="flex-row input-view" style="margin-top: 16rpx;">
				<image class="input-left-img" src="../../static/img/password.png" mode="scaleToFill"></image>
				<view class="search-input">
					<input class="search-input" type="password" placeholder-class="input-placeholder" placeholder="请输入旧密码"
						v-model="oldPwd">
				</view>
			</view>
			<view class="flex-row input-view" style="margin-top: 16rpx;">
				<image class="input-left-img" src="../../static/img/password.png" mode="scaleToFill"></image>
				<view class="search-input">
					<input class="search-input" type="password" placeholder-class="input-placeholder" placeholder="请输入新密码"
						v-model="newPwd">
				</view>
			</view>
		</view>
		<view class="submit-btn" @tap="handleChangePassword">
			<text>立即修改</text>
		</view>
	</view>
</template>

<script>
	import { mapState, mapMutations } from 'vuex'
	var that;
	export default {
		data() {
			return {
				isFocus: true,     // 输入框焦点
				userCode: '',
				oldPwd: '',
				newPwd: '',
				password: ''
			}
		},
		computed: {
			...mapState({
				userInfo: state => state.userInfo, // userInfo
				Token: state => state.Token, // Token
			})  
		},
		onLoad() {
			that = this
		},
		onShow() {
			that.getServerData()
		},
		methods: {
			getServerData() {
				
			},
			handleChangePassword() {
				if(that.userCode.trim() === '') {
					that.$common.showNormalToast('请输入您的账号！');
					return;
				}
				if(that.oldPwd.trim() === '') {
					that.$common.showNormalToast('请输入您的旧密码！');
					return;
				}
				if(that.newPwd.trim() === '') {
					that.$common.showNormalToast('请输入您的新密码！');
					return;
				}
				that.changePassword()
			},
			changePassword() {
				let requestData = {
					MethodCode: "App_ChangeUserPassword",
					Token: that.Token,
					Info: {
						UserCode: that.userCode,
						UserPasswordOld: that.$common.MD5(that.oldPwd).toUpperCase(),
						UserPasswordNew: that.$common.MD5(that.newPwd).toUpperCase(),
					}
				};
				console.log(requestData);
				that.$request.globalRequest('', 'POST', requestData, '', 0).then(res => {
					console.log(res.data);
					uni.showToast({
						icon: 'success',
						title: '修改成功！'
					})
					// if(res.data.Data.length !== 0) {
					// 	if(res.data.Data[0].IsOk === '1') {
					// 		// 保存登录状态
							
					// 	} else {
					// 		that.$common.showNormalToast('账号或密码错误！');
					// 	}
					// }
				}).catch( res => {
					that.$common.showNormalToast(res);
					console.log(res);
				})
			},
		}
	}
</script>

<style>
@import url("../login/lgoin.css");
</style>
